<template>
  <div class="container">
    <div class="closeBtn">
      <i class="iconfont iconicon-test" @click="$router.back()"></i>
    </div>

    <div class="logo">
      <span class="iconfont iconnew"></span>
    </div>

    <div class="userName">
      <authInput
        type="text"
        placeholder="手机号码"
        rule="^\d{5,13}$"
        err_message="请输入正确的手机号"
        @input="setUserName"
      ></authInput>
    </div>

    <div class="nickName">
      <authInput
        type="text"
        placeholder="昵称"
        rule="^.{2,12}$"
        err_message="请输入正确的昵称"
        @input="setNickName"
      ></authInput>
    </div>

    <div class="password">
      <authInput
        type="text"
        placeholder="密码"
        rule="^[a-z0-9_-]{6,12}$"
        err_message="请输入6~12位密码"
        @input="setPassWord"
      ></authInput>
    </div>

    <div class="registerBtn">
      <authBtn text="注册" @send="sendRegister" />
    </div>
  </div>
</template>

<script>
import authInput from "../components/authInput";
import authBtn from "../components/authBtn";
export default {
  components: {
    authInput,
    authBtn
  },
  data() {
    return {
      username: "",
      password: "",
      nickname: ""
    };
  },
  methods: {
    setUserName(val) {
      this.username = val;
    },
    setNickName(val) {
      this.nickname = val;
    },
    setPassWord(val) {
      this.password = val;
    },
    async sendRegister() {
      // 判断内容是否存在
      if (this.username == '' || this.password == '' || this.nickname== '') {
        this.$toast.fail("输入内容不能为空");
        return;
      }
      const {username,nickname,password} = this;
      const params = {username,nickname,password}

      const res = await this.$api.register(params)
      if(res){
        this.$toast.success('注册成功');
        let timer = setTimeout(()=>{
          clearTimeout(timer)
          this.$router.back()
        },1000)
      }
    }
  }
};
</script>

<style lang="less" scoped>
.container {
  padding: 5.333vw;

  .closeBtn {
    margin-bottom: 5vw;
    i {
      font-size: 7.222vw;
      color: #333;
    }
  }

  .logo{
    margin-bottom: 5vw;
    text-align: center;

    span{
      font-size: 34.444vw;
      color: #d81e06;
    }
  }
}
</style>